﻿using AutoMapper;
using MediatR;
using SupplyChain.Domain.Entities;
using SupplyChain.Infrastructure.Interface;
using SupplyChain.Write.API.Application.Command.Goods;

namespace SupplyChain.Write.API.Application.CommandHandler.Goods
{
    public class DelGoodsHandler : IRequestHandler<DelGoodsCommand, bool>
    {
        private readonly IBaseRepository<GoodsInfo> repository;

        public DelGoodsHandler(IBaseRepository<GoodsInfo> repository)
        {
            this.repository = repository;
        }
        public async Task<bool> Handle(DelGoodsCommand request, CancellationToken cancellationToken)
        {
            GoodsInfo goods=await repository.GetByPrimaryKeyAsync(request.Id);
            goods.IsDel = true;
            return await Task.FromResult(await repository.UpdateAsync(goods));
        }
    }
}
